<?php
/**
 * Created by PhpStorm.
 * User: yuanjie
 * Date: 2017/5/4
 * Time: 下午5:41
 */
class PosJoinController extends BaseController
{
    public function check(){
        $validator = Validator::make(Input::all(),
            array(
                'signature' => 'required',
                "timestamp"=>'required',
                "nonce"=>'required',
                "event"=>'required',
                "echo_str"=>'required',
            )
        );
        $response = array('code' => 0, 'msg' => 'ok');
        $checkSign = '';
        do{
            if($validator->fails()) {
                $response = Lang::get("error.args_error_10000");
                break;
            }
            $signature = Input::get('signature');
            $timestamp = Input::get('timestamp');
            $nonce = Input::get('nonce');
            $event = Input::get('event');
            $echo_str = Input::get('echo_str');

            $signData = array(
                'timestamp' => $timestamp,
                'nonce' => $nonce,
                'event' => $event,
                'echo_str' => $echo_str
            );

            $checkSign = Pos::Sign($signData,'has1');
            if($checkSign == $signature){
                $response = array(
                    'status' => 0,
                    'info' => 'success',
                    'data' => array(
                        'echo_str' => $echo_str
                    )
                );
            }
        }while(false);
        Log::info("info", array("system" => "pos" ,"event" => "check", 'input' =>Input::all() ,'sign' => $checkSign ,"output" => $response));
        return json_encode($response);
    }
}